// pages/account/account.js
import api from '../../../api/api.js'
import utils from '../../templates/loader/loader.js'
//获取应用实例
var app = getApp()
Page({
  data: {
    loginInfo: []
  },
  onLoad: function () {
    var that = this
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
  },
  onShow: function () {
    var that = this
    //获取登录信息
    api.getUser({
      done: (user) => {
        var jsonStr = '{"REQ_HEAD":{"SIGN":"null"},"REQ_BODY":{"userId":"' + user.id + '"}}'
        api.getUserOrderCount({
          method: 'POST',
          data: {
            REQ_MESSAGE: jsonStr
          },
          success: (res) => {
            that.setData({
              count: res.rows,
              loginInfo: user
            });
          }
        })
      },
      fail: () => {
        that.setData({
          loginInfo: [],
          count: []
        })
      }
    })
  }
})